package com.mfz.common.definition.symbol


/**
 * 表示状态的类
 */
class Flag(override val id: Int, override val name: String) : Symbol() {
	companion object : Iterable<Flag> {
		//保存注册到自己的所有对象
		private val arrays = arrayListOf<Flag>()

		val UNKNOWN = Flag(0, "未知状态")
		val TRUE = Flag(1, "状态:真")
		val FALSE = Flag(0, "状态:假")
		val DELETE = Flag(-1, "已删除")

		override fun iterator(): Iterator<Flag> {
			return arrays.iterator()
		}

		fun findById(value: Int): Flag {
			for (element in this) if (element.id == value) return element
			return UNKNOWN
		}

		fun findByName(name: String): Flag {
			for (element in this) if (element.name == name) return element
			return UNKNOWN
		}
	}

	val notDelete: Boolean get() = id >= 0

	init {
		arrays.add(this)
	}
}
